package com.chookss.view;

import android.content.Context;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chookss.R;
import com.chookss.tools.MyToast;
import com.chookss.tools.Utils;
import com.chookss.view.listener.StudyDialogListener;

import butterknife.BindView;

public class InitEditDialog extends BaseDialog {


    @BindView(R.id.tvTiltle)
    TextView tvTiltle;
    @BindView(R.id.tvContent)
    TextView tvContent;
    @BindView(R.id.tvSure)
    TextView tvSure;
    @BindView(R.id.tvEdit)
    EditText tvEdit;
    @BindView(R.id.viewEmpty)
    View viewEmpty;
    private int type;
    private Context context;
    private boolean idEdit=false;//是否可以编辑
    private StudyDialogListener listener=null;
    public InitEditDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_init_edit;
    }

    @Override
    protected void init(View view) {
        initCenter(0.3f);
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    if(idEdit){
                        if(Utils.isNull(tvEdit.getText().toString())){
                            MyToast.show("打卡说明不能为空");
                            return;
                        }else{
                            listener.onStudyClick(tvEdit.getText().toString());
                        }
                    }else{
                        listener.onStudyClick("");
                    }
                }
                dismiss();
            }
        });
    }

    public InitEditDialog(@NonNull Context context, String title, String content, String sure) {
        super(context);
        this.context = context;
        tvTiltle.setText(title);
        tvContent.setText(content);
        tvSure.setText(sure);
    }
    public InitEditDialog(@NonNull Context context, String title, String content, String sure, boolean edit, StudyDialogListener listener) {
        super(context);
        this.context = context;
        this.listener=listener;
        this.idEdit=edit;
        tvTiltle.setText(title);
        tvContent.setText(content);
        tvSure.setText(sure);
        if(idEdit){
            viewEmpty.setVisibility(View.GONE);
            tvEdit.setVisibility(View.VISIBLE);
        }else{
            viewEmpty.setVisibility(View.VISIBLE);
            tvEdit.setVisibility(View.GONE);
        }
    }

}
